﻿using B.S.Outsourcing.Domain;
using B.S.Outsourcing.ErrorCode;
using B.S.Outsourcing.Infatructrue;
using B.S.Outsourcing.Writer.Api.Application.Command.OutsourcingMaterialReleaseOrderModel;
using MediatR;

namespace B.S.Outsourcing.Writer.Api.Application.CommandHandler.OutsourcingMaterialReleaseOrderModel
{
    public class DeleteOutSourReleaseOrderCommandHandler : IRequestHandler<DeleteOutSourReleaseOrderCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<OutsourcingMaterialReleaseOrder> baseRepository;
        private readonly DBHelper1 dbHelper;

        public DeleteOutSourReleaseOrderCommandHandler(IBaseRepository<OutsourcingMaterialReleaseOrder> baseRepository, DBHelper1 dbHelper)
        {
            this.baseRepository = baseRepository;
            this.dbHelper = dbHelper;
        }

        public async Task<ApiResult<int>> Handle(DeleteOutSourReleaseOrderCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            var list = $"update OutsourcingMaterialReleaseOrderModel set IsDelete=1 where Id={request.Id}";
            var str = dbHelper.NonQuery(list);
            if (str > 0)
            {
                result.Code = ApiEnums.成功;
                result.Message = "成功";
                result.Data = str;
            }
            else
            {
                result.Code = ApiEnums.失败;
                result.Message = "失败";
                result.Data = str;
            }
            return await Task.FromResult(result);
        }
    }
}
